<?php
/**
 * FlickrPhotosetsDatabase class file
 * @package FlickrPhotosetsDB
 */

/**
 * Defines the operations needed for the database.
 * 
 * @package FlickrPhotosetsDB
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @version 7.10.18
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 * @since Class available since Release 2.0
 */
abstract class FlickrPhotosetsDatabase {
	
	// Abstract functions to implement depending on database type
	public abstract function get_info($uid);
	public abstract function get_uid_from_nsid($nsid);
	public abstract function log_install($uid);
	public abstract function log_notification($uid, $type, $success, $extra = '');
	public abstract function log_remove($uid, $extra = '');
	public abstract function log_update($uid, $extra = '');
	public abstract function save_config($config);
	public abstract function set_facebook_info($uid, $session_key);
	public abstract function set_last_photo($uid, $pid);
	public abstract function set_photosets($uid, $photosets);
	public abstract function store_token($uid, $nsid, $token);
	public abstract function remove_flickr_auth($uid);
	public abstract function remove_user($uid);
	
	/**
	 * Sanitizes information to be put in the database.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param string $value The value to clean
	 * @return string The SQL-safe value
	 */
	public final function sql_clean($value) {
		if (get_magic_quotes_gpc()) {
			if (ini_get('magic_quotes_sybase')) {
				$value = str_replace("''", "'", $value);
			}
			else {
				$value = stripslashes($value);
			}
		}
		$value = mysql_real_escape_string($value);
		return htmlentities($value);
	}
	
	/**
	 * Sanitizes an entire array.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param array $array The array to sanitize
	 * @return array The SQL-safe array
	 */
	public final function sql_clean_array($array) {
		$cleaned = array();
		foreach ($array as $key => $item) {
			$key = $this->sql_clean($key);
			$item = $this->sql_clean($item);
			$cleaned[$key] = $item;
		}
		return $cleaned;
	}
	
}

?>